// 检查用户是否已登录
export const checkUserAuth = () => {
    const userInfo = localStorage.getItem('userInfo')
    return !!userInfo
}

// 获取用户信息
export const getUserInfo = () => {
    const userInfo = localStorage.getItem('userInfo')
    return userInfo ? JSON.parse(userInfo) : null
}

// 设置用户信息
export const setUserInfo = (info) => {
    localStorage.setItem('userInfo', JSON.stringify(info))
}

// 清除用户信息
export const clearUserInfo = () => {
    localStorage.removeItem('userInfo')
}

// 获取默认选中的学生信息
export const getDefaultChild = () => {
    const userInfo = getUserInfo();
    if (!userInfo || !userInfo.children) return null;
    return userInfo.children.find(child => child.is_default === 1);
}